package com.library.web.controller.app;

import com.library.common.core.domain.AjaxResult;
import com.library.common.utils.SecurityUtils;
import com.library.domain.MbSignRecord;
import com.library.service.IAppLoginService;
import com.library.service.IMbSignRecordService;
import lombok.extern.slf4j.Slf4j;
import org.aspectj.weaver.loadtime.Aj;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.text.ParseException;

/**
 * @author wanghongjie
 */
@Slf4j
@RestController
@RequestMapping("/app/userInfo")
public class AppUserInfoController {
    @Autowired
    private IAppLoginService appLoginService;
    @Resource
    private IMbSignRecordService mbSignRecordService;

    @GetMapping
    public AjaxResult userInfo() {
        return appLoginService.userInfo();
    }

    @GetMapping("sign")
    public AjaxResult signIn() throws ParseException {
        MbSignRecord signRecord = new MbSignRecord();
        signRecord.setMembersId(SecurityUtils.getUserId());
        if (mbSignRecordService.isSign(signRecord)) {
            mbSignRecordService.insertMbSignRecord(signRecord);
        } else {
            return AjaxResult.error("用户已签到");
        }
        return AjaxResult.success();
    }
}
